export default {
  props: {
    valueKey: {
      type: String,
      default: 'value',
    },
    labelKey: {
      type: String,
      default: 'label',
    },
    clearable: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      provinceList: [
        {
          value: '1',
          label: '黄金糕',
        },
        {
          value: '2',
          label: '双皮奶',
        },
      ],
      cityList: [
        {
          value: '选项1',
          label: '黄金糕',
        },
        {
          value: '选项2',
          label: '双皮奶',
        },
      ],
      areaList: [
        {
          value: '选项1',
          label: '黄金糕',
        },
        {
          value: '选项2',
          label: '双皮奶',
        },
      ],
    };
  },
  methods: {
    // 切换省市县
    changeAddressSelectHandler(value, column, key) {
      console.log(value, column, '切换');
      const { prop, changeMethod } = column;
      let label = '';
      if (key == 'provinceAddress') {
        // TODO 根据省份接口查询市接口
        label = this.provinceList.find((item) => item.value === value)?.label;
      } else if (key == 'cityAddress') {
        // TODO 根据市查询地区接口
        label = this.cityList.find((item) => item.value === value)?.label;
      } else if (key == 'areaAddress') {
        // TODO 不需要处理
        label = this.areaList.find((item) => item.value === value)?.label;
      }
      if (typeof changeMethod === 'function') {
        changeMethod(val);
      } else {
        this.$emit(changeMethod, { val: value, prop, label });
      }
    },
    // 清除操作
    clearAddressSelectHandler(query, column) {
      const { clearMethod, prop } = column;
      query[prop] = '';
      for (const item of column?.clearRelation ?? []) {
        query[item] = '';
      }
      if (!clearMethod) {
        return;
      }
      this.$emit(clearMethod, { prop });
    },
  },
};
